import { defineConfig, loadEnv } from "vite"
import { resolve } from "path"
import { wrapperEnv, createVitePlugin } from "./build/vite"
import { __APP_INFO__ } from "./build/info"

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
    const env = wrapperEnv(loadEnv(mode, process.cwd()))
    const { VITE_APP_PREFIX, VITE_APP_PORT } = env
    const isBuild = command === "build"
    return {
        base: VITE_APP_PREFIX,
        resolve: {
            alias: [
                {
                    find: "@",
                    replacement: resolve(process.cwd(), "./src")
                }
            ]
        },
        define: {
            __APP_INFO__: JSON.stringify(__APP_INFO__)
        },
        plugins: createVitePlugin(env, isBuild),
        server: {
            port: VITE_APP_PORT
        }
    }
})
